package com.emn.fil.automaticdiscover.ihm.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.emn.fil.automaticdiscover.ihm.dialogs.AdvancedCFGDialog;

public class BtnAddOSXDialAdvCfg implements ActionListener {

	AdvancedCFGDialog my_dialog;

	public void actionPerformed(ActionEvent e) {
		String textBoxContent = this.my_dialog.getTxtbox_mac().getText();
		
		// Replace all white spaces of the String
		textBoxContent = textBoxContent.replaceAll("\\s","" );
		
		if (!(textBoxContent.isEmpty()) && (textBoxContent.matches("[1-9].[0-9]*"))) {
			int textBoxContentInt = Integer.parseInt(textBoxContent);
			if (!(this.my_dialog.getDlm_ports_mac().contains(textBoxContentInt))
					&& !(this.my_dialog.getDlm_ports_unix()
							.contains(textBoxContentInt))
					&& !(this.my_dialog.getDlm_ports_win()
				.contains(textBoxContentInt))) {
					this.my_dialog.getDlm_ports_mac().addElement(textBoxContentInt);
				}
		}
		this.my_dialog.getTxtbox_mac().setText("");
	}

	public BtnAddOSXDialAdvCfg(AdvancedCFGDialog my_dialog) {
		this.my_dialog = my_dialog;
	}

}
